//
// Copyright (C) 2011 - 2013  Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1
//#include "stdafx.h"
#include "AbcdAtmVolCurve.h"
using namespace Cephei::QL::Experimental::Volatility;
#include <gen/QL/Times/Calendar.h>
#include <gen/QL/Times/Period.h>
#include <gen/QL/Quote.h>
#include <gen/QL/Times/DayCounter.h>
#include <gen/QL/Experimental/Volatility/BlackAtmVolCurve.h>
using namespace Cephei::QL::Times;
using namespace Cephei::QL;
#define HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Experimental::Volatility::CAbcdAtmVolCurve::CAbcdAtmVolCurve (UInt32 settlementDays, Cephei::QL::Times::ICalendar^ cal, Cephei::Core::IVector<Cephei::QL::Times::IPeriod^>^ optionTenors, Cephei::Core::IVector<Cephei::QL::IQuote^>^ volsHandles, Microsoft::FSharp::Core::FSharpOption<Cephei::Core::IVector<Boolean>^>^ inclusionInInterpolationFlag, Microsoft::FSharp::Core::FSharpOption<QL::Times::BusinessDayConventionEnum>^ bdc, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IDayCounter^>^ dc) : CBlackAtmVolCurve(CAbcdAtmVolCurve::typeid)
{
    CCalendar^ _Ccal;
    CDayCounter^ _Cdc;
    try
    {
#ifdef HANDLE
        _phAbcdAtmVolCurve = NULL;
#endif
        QuantLib::Natural _settlementDays = (QuantLib::Natural)ValueHelper::Convert (settlementDays); //d
        _Ccal = safe_cast<CCalendar^> (cal);
        _Ccal->Lock();
        QuantLib::Calendar& _cal = static_cast<QuantLib::Calendar&> (_Ccal->GetReference ()); 
        optionTenors ->Lock ();
        INativeVector<Cephei::QL::Times::IPeriod^>^ _NCIoptionTenors = optionTenors->getFeature (NativeFeature::Value);
        CPeriodVector^ _NCoptionTenors = safe_cast<CPeriodVector^>(_NCIoptionTenors);
        std::vector<QuantLib::Period>& _optionTenors = static_cast<std::vector<QuantLib::Period>&> (_NCoptionTenors->GetReference ());
        volsHandles ->Lock ();
        INativeVector<Cephei::QL::IQuote^>^ _NCIvolsHandles = volsHandles->getFeature (NativeFeature::Handle);
        CQuoteVector^ _NCvolsHandles = safe_cast<CQuoteVector^>(_NCIvolsHandles);
        std::vector<Handle<QuantLib::Quote> >& _volsHandles = static_cast<std::vector<Handle<QuantLib::Quote> >&> (_NCvolsHandles->GetHandle ());
        CBooleanVector^ _NCinclusionInInterpolationFlag;
        if (Microsoft::FSharp::Core::FSharpOption<Cephei::Core::IVector<Boolean>^>::IsSome::get (inclusionInInterpolationFlag))
        {
            inclusionInInterpolationFlag->Value->Lock();
            INativeVector<Boolean>^ _NCIinclusionInInterpolationFlag = inclusionInInterpolationFlag->Value->getFeature (NativeFeature::Value);
            _NCinclusionInInterpolationFlag = safe_cast<CBooleanVector^>(_NCIinclusionInInterpolationFlag);
        }
        std::vector<bool> _inclusionInInterpolationFlag = 
            (Microsoft::FSharp::Core::FSharpOption<Cephei::Core::IVector<Boolean>^>::IsSome::get (inclusionInInterpolationFlag) ? static_cast<std::vector<bool>> (_NCinclusionInInterpolationFlag->GetReference ()) : std::vector<bool>(1, true)); //3
        QuantLib::BusinessDayConvention _bdc = 
            (Microsoft::FSharp::Core::FSharpOption<QL::Times::BusinessDayConventionEnum>::IsSome::get (bdc) ? (QuantLib::BusinessDayConvention)bdc->Value : QuantLib::BusinessDayConvention::Following); //10
        if (Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IDayCounter^>::IsSome::get (dc))
        {
            _Cdc = safe_cast<CDayCounter^> (dc->Value);
            _Cdc->Lock();
        }
        QuantLib::DayCounter& _dc = 
            (Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IDayCounter^>::IsSome::get (dc) ? static_cast<QuantLib::DayCounter&> (_Cdc->GetReference ()) : QuantLib::Actual365Fixed()); //1
        _ppAbcdAtmVolCurve = new boost::shared_ptr<QuantLib::AbcdAtmVolCurve> (new QuantLib::AbcdAtmVolCurve ( _settlementDays,  _cal,  _optionTenors,  _volsHandles,  _inclusionInInterpolationFlag,  _bdc,  _dc ));
        SetBlackAtmVolCurve (boost::dynamic_pointer_cast<QuantLib::BlackAtmVolCurve> (*_ppAbcdAtmVolCurve));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (_Ccal != nullptr) _Ccal->Unlock();
        if (optionTenors != nullptr) optionTenors->Unlock();    //not optional
        if (volsHandles != nullptr) volsHandles->Unlock();    //not optional
        if (inclusionInInterpolationFlag != nullptr) inclusionInInterpolationFlag->Value->Unlock();
        if (_Cdc != nullptr) _Cdc->Unlock();
    }
}
Cephei::QL::Experimental::Volatility::CAbcdAtmVolCurve::CAbcdAtmVolCurve (boost::shared_ptr<QuantLib::AbcdAtmVolCurve>& childNative, Object^ owner) : CBlackAtmVolCurve(CAbcdAtmVolCurve::typeid)
{
#ifdef HANDLE
	_phAbcdAtmVolCurve = NULL;
#endif
	_ppAbcdAtmVolCurve = &childNative;
    _ppBlackAtmVolCurve = new boost::shared_ptr<QuantLib::BlackAtmVolCurve> (boost::dynamic_pointer_cast<QuantLib::BlackAtmVolCurve> (*_ppAbcdAtmVolCurve));
}
Cephei::QL::Experimental::Volatility::CAbcdAtmVolCurve::CAbcdAtmVolCurve (QuantLib::AbcdAtmVolCurve& childNative, Object^ owner) : CBlackAtmVolCurve(CAbcdAtmVolCurve::typeid)
{
#ifdef HANDLE
	_phAbcdAtmVolCurve = NULL;
#endif
	_ppAbcdAtmVolCurve = new boost::shared_ptr<QuantLib::AbcdAtmVolCurve> (&childNative);
    _ppBlackAtmVolCurve = new boost::shared_ptr<QuantLib::BlackAtmVolCurve> (boost::dynamic_pointer_cast<QuantLib::BlackAtmVolCurve> (*_ppAbcdAtmVolCurve));
    _AbcdAtmVolCurveOwner = owner;
    _BlackAtmVolCurveOwner = owner;
}

Cephei::QL::Experimental::Volatility::CAbcdAtmVolCurve::CAbcdAtmVolCurve (CAbcdAtmVolCurve^ copy) : CBlackAtmVolCurve(CAbcdAtmVolCurve::typeid)
{
#ifdef HANDLE
	_phAbcdAtmVolCurve = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppAbcdAtmVolCurve = new boost::shared_ptr<QuantLib::AbcdAtmVolCurve> (copy->GetShared());
        _ppBlackAtmVolCurve = new boost::shared_ptr<QuantLib::BlackAtmVolCurve> (boost::dynamic_pointer_cast<QuantLib::BlackAtmVolCurve> (*_ppAbcdAtmVolCurve));
    }
}
Cephei::QL::Experimental::Volatility::CAbcdAtmVolCurve::CAbcdAtmVolCurve (PLATFORM::Type^ t) : CBlackAtmVolCurve(CAbcdAtmVolCurve::typeid)
{
#ifdef HANDLE
	_phAbcdAtmVolCurve = NULL;
#endif
	if (!t->IsSubclassOf(CAbcdAtmVolCurve::typeid))
		throw REFNEW Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Experimental::Volatility::CAbcdAtmVolCurve::CAbcdAtmVolCurve (QuantLib::Handle<QuantLib::AbcdAtmVolCurve>& childNative, Object^ owner)  : CBlackAtmVolCurve(CAbcdAtmVolCurve::typeid)
{
	_phAbcdAtmVolCurve = &childNative;
	_ppAbcdAtmVolCurve = &static_cast<boost::shared_ptr<QuantLib::AbcdAtmVolCurve>>(childNative.currentLink());
    _ppBlackAtmVolCurve = new boost::shared_ptr<QuantLib::BlackAtmVolCurve> (boost::dynamic_pointer_cast<QuantLib::BlackAtmVolCurve> (*_ppAbcdAtmVolCurve));
    _AbcdAtmVolCurveOwner = owner;
}
Cephei::QL::Experimental::Volatility::CAbcdAtmVolCurve::CAbcdAtmVolCurve (QuantLib::Handle<QuantLib::AbcdAtmVolCurve> childNative)  : CBlackAtmVolCurve(CAbcdAtmVolCurve::typeid)
{
	_phAbcdAtmVolCurve = &childNative;
	_ppAbcdAtmVolCurve = &static_cast<boost::shared_ptr<QuantLib::AbcdAtmVolCurve>>(childNative.currentLink());
    _ppBlackAtmVolCurve = new boost::shared_ptr<QuantLib::BlackAtmVolCurve> (boost::dynamic_pointer_cast<QuantLib::BlackAtmVolCurve> (*_ppAbcdAtmVolCurve));
}
#endif
#ifdef STRUCT
Cephei::QL::Experimental::Volatility::CAbcdAtmVolCurve::CAbcdAtmVolCurve (QuantLib::AbcdAtmVolCurve childNative)  : CBlackAtmVolCurve(CAbcdAtmVolCurve::typeid)
{
#ifdef HANDLE
	_phAbcdAtmVolCurve = NULL;
#endif
	_ppAbcdAtmVolCurve = new boost::shared_ptr<QuantLib::AbcdAtmVolCurve> (new QuantLib::AbcdAtmVolCurve (childNative));
    _ppBlackAtmVolCurve = new boost::shared_ptr<QuantLib::BlackAtmVolCurve> (boost::dynamic_pointer_cast<QuantLib::BlackAtmVolCurve> (*_ppAbcdAtmVolCurve));
}
#endif

Cephei::QL::Experimental::Volatility::CAbcdAtmVolCurve::~CAbcdAtmVolCurve ()
{
    if (_ppAbcdAtmVolCurve != NULL)
    {
	    delete _ppAbcdAtmVolCurve;
        _ppAbcdAtmVolCurve = NULL;
    }
}
Cephei::QL::Experimental::Volatility::CAbcdAtmVolCurve::!CAbcdAtmVolCurve ()
{
    if (_ppAbcdAtmVolCurve != NULL)
    {
	    delete _ppAbcdAtmVolCurve;
    }
}
QuantLib::AbcdAtmVolCurve& Cephei::QL::Experimental::Volatility::CAbcdAtmVolCurve::GetReference ()
{
    if (_ppAbcdAtmVolCurve == NULL) throw REFNEW NativeNullException ();
	return **_ppAbcdAtmVolCurve;
}
boost::shared_ptr<QuantLib::AbcdAtmVolCurve>& Cephei::QL::Experimental::Volatility::CAbcdAtmVolCurve::GetShared ()
{
    if (_ppAbcdAtmVolCurve == NULL) throw REFNEW NativeNullException ();
	return *_ppAbcdAtmVolCurve;
}
QuantLib::AbcdAtmVolCurve* Cephei::QL::Experimental::Volatility::CAbcdAtmVolCurve::GetPointer ()
{
    if (_ppAbcdAtmVolCurve == NULL) throw REFNEW NativeNullException ();
	return &**_ppAbcdAtmVolCurve;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::AbcdAtmVolCurve>& Cephei::QL::Experimental::Volatility::CAbcdAtmVolCurve::GetHandle ()
{
	if (_phAbcdAtmVolCurve == NULL)
	{
		_phAbcdAtmVolCurve = new Handle<QuantLib::AbcdAtmVolCurve> (*_ppAbcdAtmVolCurve);
	}
	return *_phAbcdAtmVolCurve;
}
#endif
bool Cephei::QL::Experimental::Volatility::CAbcdAtmVolCurve::HasNative () 
{
	return (_ppAbcdAtmVolCurve != NULL);
}

Double Cephei::QL::Experimental::Volatility::CAbcdAtmVolCurve::A::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppAbcdAtmVolCurve)->a ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Experimental::Volatility::CAbcdAtmVolCurve::B::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppAbcdAtmVolCurve)->b ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Experimental::Volatility::CAbcdAtmVolCurve::C::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppAbcdAtmVolCurve)->c ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Experimental::Volatility::CAbcdAtmVolCurve::D::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppAbcdAtmVolCurve)->d ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Experimental::Volatility::CAbcdAtmVolCurve::K (Double t)
{
    try
    {
        QuantLib::Time _t = (QuantLib::Time)ValueHelper::Convert (t); //a
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppAbcdAtmVolCurve)->k ( _t );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::Core::IVector<Double>^ Cephei::QL::Experimental::Volatility::CAbcdAtmVolCurve::K ()
{
    try
    {
    	std::vector<QuantLib::Real> _rv = (std::vector<QuantLib::Real>)(*_ppAbcdAtmVolCurve)->k ( );   
        Cephei::Core::IVector<Double>^ _nrv = REFNEW CoVector<Double> (REFNEW CDoubleVector (_rv));
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
DateTime Cephei::QL::Experimental::Volatility::CAbcdAtmVolCurve::MaxDate::get ()
{
    try
    {
    	QuantLib::Date _rv = (QuantLib::Date)(*_ppAbcdAtmVolCurve)->maxDate ( );   
        DateTime _nrv = (DateTime)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Experimental::Volatility::CAbcdAtmVolCurve::MaxError::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppAbcdAtmVolCurve)->maxError ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Experimental::Volatility::CAbcdAtmVolCurve::MaxStrike::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppAbcdAtmVolCurve)->maxStrike ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Experimental::Volatility::CAbcdAtmVolCurve::MinStrike::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppAbcdAtmVolCurve)->minStrike ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::Core::IVector<DateTime>^ Cephei::QL::Experimental::Volatility::CAbcdAtmVolCurve::OptionDates::get ()
{
    try
    {
    	std::vector<QuantLib::Date>& _rv = (std::vector<QuantLib::Date>&)(*_ppAbcdAtmVolCurve)->optionDates ( );   
        Cephei::Core::IVector<DateTime>^ _nrv = REFNEW CoVector<DateTime> (REFNEW CDateTimeVector (_rv));
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::Core::IVector<Cephei::QL::Times::IPeriod^>^ Cephei::QL::Experimental::Volatility::CAbcdAtmVolCurve::OptionTenors::get ()
{
    try
    {
    	std::vector<QuantLib::Period>& _rv = (std::vector<QuantLib::Period>&)(*_ppAbcdAtmVolCurve)->optionTenors ( );   
        CoVector<Cephei::QL::Times::IPeriod^>^ _nrv = REFNEW CoVector<Cephei::QL::Times::IPeriod^>(REFNEW CPeriodVector (_rv, this));
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::Core::IVector<Cephei::QL::Times::IPeriod^>^ Cephei::QL::Experimental::Volatility::CAbcdAtmVolCurve::OptionTenorsInInterpolation::get ()
{
    try
    {
    	std::vector<QuantLib::Period>& _rv = (std::vector<QuantLib::Period>&)(*_ppAbcdAtmVolCurve)->optionTenorsInInterpolation ( );   
        CoVector<Cephei::QL::Times::IPeriod^>^ _nrv = REFNEW CoVector<Cephei::QL::Times::IPeriod^>(REFNEW CPeriodVector (_rv, this));
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::Core::IVector<Double>^ Cephei::QL::Experimental::Volatility::CAbcdAtmVolCurve::OptionTimes::get ()
{
    try
    {
    	std::vector<QuantLib::Time>& _rv = (std::vector<QuantLib::Time>&)(*_ppAbcdAtmVolCurve)->optionTimes ( );   
        Cephei::Core::IVector<Double>^ _nrv = REFNEW CoVector<Double> (REFNEW CDoubleVector (_rv));
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Experimental::Volatility::IAbcdAtmVolCurve^ Cephei::QL::Experimental::Volatility::CAbcdAtmVolCurve::PerformCalculations::get ()
{
    try
    {
    	(*_ppAbcdAtmVolCurve)->performCalculations ( );
    	return this;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Experimental::Volatility::CAbcdAtmVolCurve::RmsError::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppAbcdAtmVolCurve)->rmsError ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Experimental::Volatility::IAbcdAtmVolCurve^ Cephei::QL::Experimental::Volatility::CAbcdAtmVolCurve::Update::get ()
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
    	(*_ppAbcdAtmVolCurve)->update ( );
    	return this;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
QL::Math::Optimization::EndCriteria::TypeEnum Cephei::QL::Experimental::Volatility::CAbcdAtmVolCurve::EndCriteria::get ()
{
    try
    {
    	QuantLib::EndCriteria::Type _rv = (QuantLib::EndCriteria::Type)(*_ppAbcdAtmVolCurve)->endCriteria ( );   
        QL::Math::Optimization::EndCriteria::TypeEnum _nrv = (QL::Math::Optimization::EndCriteria::TypeEnum)_rv;
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Experimental::Volatility::CAbcdAtmVolCurveVector::CAbcdAtmVolCurveVector ()
{
#ifdef STRUCT
	_pVValue = NULL;
#endif
	_pVBoost = NULL;
#ifdef HANDLE
	_pVHand = NULL;
#endif
}
Cephei::QL::Experimental::Volatility::CAbcdAtmVolCurveVector::~CAbcdAtmVolCurveVector ()
{
#ifdef STRUCT
	if (_pVValue != NULL) delete _pVValue;
	_pVValue = NULL;
#endif   
	if (_pVBoost != NULL) delete _pVBoost;
	_pVBoost = NULL;
#ifdef HANDLE
	if (_pVHand != NULL) delete _pVHand;
	_pVHand = NULL;
#endif
}
Cephei::QL::Experimental::Volatility::CAbcdAtmVolCurveVector::!CAbcdAtmVolCurveVector ()
{
#ifdef STRUCT
	if (_pVValue != NULL) delete _pVValue;
#endif   
	if (_pVBoost != NULL) delete _pVBoost;
#ifdef HANDLE
	if (_pVHand != NULL) delete _pVHand;
#endif
}
#ifdef STRUCT
Cephei::QL::Experimental::Volatility::CAbcdAtmVolCurveVector::CAbcdAtmVolCurveVector (std::vector<QuantLib::AbcdAtmVolCurve>& vec, Object^ owner)
{
#ifdef STRUCT
	_pVValue = NULL;
#endif
	_pVBoost = NULL;
#ifdef HANDLE
	_pVHand = NULL;
#endif
	_pVValue = &vec;
	_owner = owner;
}
Cephei::QL::Experimental::Volatility::CAbcdAtmVolCurveVector::CAbcdAtmVolCurveVector (std::vector<QuantLib::AbcdAtmVolCurve> vec)
{
#ifdef STRUCT
	_pVValue = NULL;
#endif
	_pVBoost = NULL;
#ifdef HANDLE
	_pVHand = NULL;
#endif
	_pVValue = new std::vector<QuantLib::AbcdAtmVolCurve> (vec);
}
#endif
Cephei::QL::Experimental::Volatility::CAbcdAtmVolCurveVector::CAbcdAtmVolCurveVector (std::vector<boost::shared_ptr<QuantLib::AbcdAtmVolCurve>>& vec, Object^ owner)
{
#ifdef STRUCT
	_pVValue = NULL;
#endif
	_pVBoost = NULL;
#ifdef HANDLE
	_pVHand = NULL;
#endif
	 _pVBoost = &vec;
	_owner = owner;
}
#ifdef HANDLE
Cephei::QL::Experimental::Volatility::CAbcdAtmVolCurveVector::CAbcdAtmVolCurveVector (std::vector<QuantLib::Handle<QuantLib::AbcdAtmVolCurve>>& vec, Object^ owner)
{
#ifdef STRUCT
	_pVValue = NULL;
#endif
	_pVBoost = NULL;
#ifdef HANDLE
	_pVHand = NULL;
#endif
	 _pVHand = &vec;
	_owner = owner;
}
#endif

int Cephei::QL::Experimental::Volatility::CAbcdAtmVolCurveVector::Count::get ()
{
#ifdef STRUCT
	if (_pVValue != NULL) 
	{
		return _pVValue->size();
	}
#endif    
	if (_pVBoost != NULL)
	{
		return _pVBoost->size ();
	}
#ifdef HANDLE
	if (_pVHand != NULL)
	{
		return _pVHand->size ();
	}
#endif
	return 0;		// should never happen
}
Cephei::QL::Experimental::Volatility::IAbcdAtmVolCurve^ Cephei::QL::Experimental::Volatility::CAbcdAtmVolCurveVector::default::get (int index) 
{
#ifdef STRUCT
	if (_pVValue != NULL) 
	{
    	if ((size_t)index >= _pVValue->size()) throw REFNEW RangeException ();
		QuantLib::AbcdAtmVolCurve& native = (*_pVValue)[index];
		return REFNEW CAbcdAtmVolCurve (native, this);
	}
#endif    
	if (_pVBoost != NULL)
	{
    	if ((size_t)index >= _pVBoost->size()) throw REFNEW RangeException ();
		QuantLib::AbcdAtmVolCurve& native = *(*_pVBoost)[index];
		return REFNEW CAbcdAtmVolCurve (native, this);
	}
#ifdef HANDLE
	if (_pVHand != NULL)
	{
    	if ((size_t)index >= _pVHand->size()) throw REFNEW RangeException ();
		QuantLib::AbcdAtmVolCurve& native = *((*_pVHand)[index].currentLink ());
		return REFNEW CAbcdAtmVolCurve (native, this);
	}
#endif
	return nullptr;		// can never be the case
}
void Cephei::QL::Experimental::Volatility::CAbcdAtmVolCurveVector::default::set (int index, Cephei::QL::Experimental::Volatility::IAbcdAtmVolCurve^ value) 
{
#ifdef STRUCT
	if (_pVValue != NULL)
	{
		if (_pVValue->size() <= (size_t)index)
		{
			// can't happen because vectors are filled from List<> sequentially
			if (_pVValue->size() < (size_t)index)
			{
				throw REFNEW RangeException ();
			}
			_pVValue->push_back (dynamic_cast<CAbcdAtmVolCurve^>(value)->GetReference ());
		}
        else
        {
            QuantLib::AbcdAtmVolCurve& c = (*_pVValue)[index];
            c = dynamic_cast<CAbcdAtmVolCurve^>(value)->GetReference ();
        }
	}
#endif   
	if (_pVBoost != NULL)
	{
		if (_pVBoost->size() <= (size_t)index)
		{
			// can't happen because vectors are filled from List<> sequentially
			if (_pVBoost->size() < (size_t)index)
			{
				throw REFNEW RangeException ();
			}
			_pVBoost->push_back (dynamic_cast<CAbcdAtmVolCurve^>(value)->GetShared ());
		}
		boost::shared_ptr<QuantLib::AbcdAtmVolCurve>& c = (*_pVBoost)[index];
		c = dynamic_cast<CAbcdAtmVolCurve^>(value)->GetShared ();
	}
#ifdef HANDLE
	if (_pVHand != NULL)
	{
		if (_pVHand->size() <= (size_t)index)
		{
			// can't happen because vectors are filled from List<> sequentially
			if (_pVHand->size() < (size_t)index)
			{
				throw REFNEW RangeException ();
			}
			_pVHand->push_back (QuantLib::Handle<QuantLib::AbcdAtmVolCurve> ());
		}
		QuantLib::Handle<QuantLib::AbcdAtmVolCurve>& c = (*_pVHand)[index];
		boost::shared_ptr<QuantLib::AbcdAtmVolCurve>& b = static_cast<boost::shared_ptr<QuantLib::AbcdAtmVolCurve>>(c.currentLink());
		b = dynamic_cast<CAbcdAtmVolCurve^>(value)->GetShared ();
	}
#endif
}
Cephei::Core::Generic::ICoCell<Cephei::QL::Experimental::Volatility::IAbcdAtmVolCurve^>^ Cephei::QL::Experimental::Volatility::CAbcdAtmVolCurveVector::CItem::get (int index) 
{
	return CellFactory::Instance->Create<IAbcdAtmVolCurve^> (dynamic_cast<IAbcdAtmVolCurve^>(default[index]));
}

void Cephei::QL::Experimental::Volatility::CAbcdAtmVolCurveVector::CItem::set (int index, Cephei::Core::Generic::ICoCell<Cephei::QL::Experimental::Volatility::IAbcdAtmVolCurve^>^ value) 
{
	default[index] = safe_cast<IAbcdAtmVolCurve^>(value->Value);
}
#ifdef STRUCT
std::vector<QuantLib::AbcdAtmVolCurve>& Cephei::QL::Experimental::Volatility::CAbcdAtmVolCurveVector::GetReference ()
{
	 return *_pVValue;
}
#endif

std::vector<boost::shared_ptr<QuantLib::AbcdAtmVolCurve>>& Cephei::QL::Experimental::Volatility::CAbcdAtmVolCurveVector::GetShared ()
{
	return *_pVBoost;
}

#ifdef HANDLE
std::vector<QuantLib::Handle<QuantLib::AbcdAtmVolCurve>>& Cephei::QL::Experimental::Volatility::CAbcdAtmVolCurveVector::GetHandle ()
{
	return *_pVHand;
}
#endif
bool Cephei::QL::Experimental::Volatility::CAbcdAtmVolCurveVector::PrepareFeature (NativeFeature feature)
{
	switch (feature)
	{
#ifdef STRUCT
		case NativeFeature::Value :
			if (_pVValue == NULL)
			{
				_pVValue = new std::vector<QuantLib::AbcdAtmVolCurve> ();
				return true;
			}
			break;
#endif
        case NativeFeature::shared_ptr :
			if (_pVBoost == NULL)
			{
				_pVBoost = new std::vector<boost::shared_ptr<QuantLib::AbcdAtmVolCurve>> ();
				return true;
			}
			break;
#ifdef HANDLE
        case NativeFeature::Handle :
            if (_pVHand == NULL)
            {
                _pVHand = new std::vector<QuantLib::Handle<QuantLib::AbcdAtmVolCurve>> ();
                return true;
            }
            break;
#endif
	}
	return false;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Experimental::Volatility::IAbcdAtmVolCurve^ Cephei::QL::Experimental::Volatility::CAbcdAtmVolCurve_Factory::Create (UInt32 settlementDays, Cephei::QL::Times::ICalendar^ cal, Cephei::Core::IVector<Cephei::QL::Times::IPeriod^>^ optionTenors, Cephei::Core::IVector<Cephei::QL::IQuote^>^ volsHandles, Microsoft::FSharp::Core::FSharpOption<Cephei::Core::IVector<Boolean>^>^ inclusionInInterpolationFlag, Microsoft::FSharp::Core::FSharpOption<QL::Times::BusinessDayConventionEnum>^ bdc, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IDayCounter^>^ dc)
{
    return REFNEW CAbcdAtmVolCurve ( settlementDays,  cal,  optionTenors,  volsHandles,  inclusionInInterpolationFlag,  bdc,  dc);
}
/* <summary>Create a single dimension array of AbcdAtmVolCurve that can be passed into other function </summary> */
IVector<Cephei::QL::Experimental::Volatility::IAbcdAtmVolCurve^>^ Cephei::QL::Experimental::Volatility::CAbcdAtmVolCurve_Factory::CreateVector ()
 {
	 return REFNEW CoVector<IAbcdAtmVolCurve^> (REFNEW CAbcdAtmVolCurveVector ());
 }
IVector<Cephei::QL::Experimental::Volatility::IAbcdAtmVolCurve^>^ Cephei::QL::Experimental::Volatility::CAbcdAtmVolCurve_Factory::CreateVector (PLATFORM::Collections::Generic::IEnumerable<IAbcdAtmVolCurve^>^ source)
 {
	 return REFNEW CoVector<IAbcdAtmVolCurve^> (source, REFNEW CAbcdAtmVolCurveVector ());
 }
/* <summary>Create a single dimension array of AbcdAtmVolCurve with change events</summary> */
Cephei::Core::Generic::ICoCell<IVector<Cephei::Core::Generic::ICoCell<Cephei::QL::Experimental::Volatility::IAbcdAtmVolCurve^>^>^>^ Cephei::QL::Experimental::Volatility::CAbcdAtmVolCurve_Factory::CreateCellVector ()
 {
	 return CellFactory::Instance->Create<IVector<Cephei::Core::Generic::ICoCell<Cephei::QL::Experimental::Volatility::IAbcdAtmVolCurve^>^>^> (REFNEW CoCellVector<Cephei::QL::Experimental::Volatility::IAbcdAtmVolCurve^> (REFNEW CAbcdAtmVolCurveVector ()));
 }
Cephei::Core::Generic::ICoCell<IVector<Cephei::Core::Generic::ICoCell<Cephei::QL::Experimental::Volatility::IAbcdAtmVolCurve^>^>^>^ Cephei::QL::Experimental::Volatility::CAbcdAtmVolCurve_Factory::CreateCellVector (PLATFORM::Collections::Generic::IEnumerable<Cephei::Core::Generic::ICoCell<Cephei::QL::Experimental::Volatility::IAbcdAtmVolCurve^>^>^ source)
 {
	 return CellFactory::Instance->Create<IVector<Cephei::Core::Generic::ICoCell<Cephei::QL::Experimental::Volatility::IAbcdAtmVolCurve^>^>^> (REFNEW CoCellVector<Cephei::QL::Experimental::Volatility::IAbcdAtmVolCurve^> (source, REFNEW CAbcdAtmVolCurveVector ()));
 }

